I'm making a POST request in cypress automation but I keep getting an authentication error. The endpoint takes basic authetication.
"error": "AuthenticationError",
"text": "Unable to find credentials in request".
Here is my request:
cy.request({
url: 'TEST ENDPOINT',
method : 'POST',
auth: {
username: 'test@test.com',
password: 'test1'
},
body: {
"firstname": "Bruce",
"lastname": "lee"
});
});
When I hit the same endpoint in POSTMAN it works as expected. Not sure what's wrong with my request.
There is no key called "auth", you should use either Header to pass your token or auth key in it.
method: 'POST',
url: url,
headers: {
'content-type': 'application/json',
'Accept': 'application/json',
'Authorization':'Bearer '+token
},
body: JSON.stringify(body)